// 类型断言

/**
 * 1. 子类可以直接断言为父类
 * 如果  A，B 如果是类 但是没有继承关系
 *  public属性或者方法跟另一个类完全相同,或者子集的时候,可以类型断言
 */
class People {
  public username!: string;
  public age!: number;
  public address!: string;
 
  constructor(username:string, age:number, address:string) {
    this.username = username;
    this.age = age;
    this.address = address;
  }
}

// ? People从属性上说,是stu的子集
class Stu {
  public username!: string;
  public age!: number;
  public address!: string; // 类型 "Stu" 中缺少属性 "address"，但类型 "typestu2" 中需要该属性。t
  public phone!: string;
  constructor(username: string, age: number, address: string) {
    this.username = username;
    this.age = age;
    this.address = address;
  }
  study() {
    console.log("Stu我在学习");
  }
}

let people = new People("墨子", 19, "北京");
// let result  = people as Stu;// ! 进行类型断言报错


let stu = new Stu("庄周", 18, "上海");

stu as People // 不会报错
stu.study()




export {};
